package com.google.code.struts2jruby.ognl;

import ognl.MethodAccessor;
import ognl.MethodFailedException;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.Map;

/**
 * This custom MethodAccessor for Ognl interfaces with the JRuby API in order
 * to invoke methods on the IRubyObjects.
 *
 * @author Richard L. Burton III
 * @see ognl.MethodAccessor
 */
public class RubyObjectMethodAccessor implements MethodAccessor {

    public Object callStaticMethod(Map context, Class clazz, String string, Object arguments[]) throws MethodFailedException {
        throw new UnsupportedOperationException("This method is not yet supported.");
    }
    
    public Object callMethod(Map context, Object instance, String name, Object arguments[]) throws MethodFailedException {
        IRubyObject ro = (IRubyObject) instance;
        Object value = ro.callMethod(ro.getRuntime().getCurrentContext(), name);
        return value;
    }
}
